package com.liujit.standard.basis.generator.engine;

import com.liujit.standard.basis.generator.util.ToolUtil;
import com.liujit.standard.basis.generator.engine.base.AbstractTemplateEngine;

/**
 * 通用的模板生成引擎
 *
 * @author fengshuonan
 * @date 2017-05-09 20:32
 */
public class TemplateEngine extends AbstractTemplateEngine {

    @Override
    protected void generateController() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getControllerConfig().getTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Controller.java.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Controller生成成功!");
    }

    @Override
    protected void generateService() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getServiceConfig().getTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Service.java.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Service生成成功!");
        String implPath = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getServiceConfig().getImplTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/ServiceImpl.java.btl", implPath);
        System.out.println(super.getContextConfig().getBizEnName() + "-ServiceImpl生成成功!");
    }

    @Override
    protected void generateMapper() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getMapperConfig().getTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Mapper.java.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Mapper生成成功!");
    }

    @Override
    protected void generateXml() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getMapperConfig().getXmlTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Mapping.xml.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Xml生成成功!");
    }

    @Override
    protected void generateModel() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getModelConfig().getTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Model.java.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Model生成成功!");
    }

    @Override
    protected void generateQuery() {
        String path = ToolUtil.format(
                super.getContextConfig().getProjectPath() + super.getQueryConfig().getTemplatePath(),
                ToolUtil.firstLetterToUpper(super.getContextConfig().getBizEnName()));
        generateFile(super.getContextConfig().getTemplatePrefixPath() + "/Query.java.btl", path);
        System.out.println(super.getContextConfig().getBizEnName() + "-Query生成成功!");
    }
}
